var username=localStorage.getItem("username");
var token=localStorage.getItem("token");
var userid=localStorage.getItem("userid");
$(function(){
	$("#preRecvTime").datetimepicker({lang:'ch',
		timepicker:false,
		format:'Y-m-d',
		formatDate:'Y-m-d'
	});

	var paramMap = params();
	var id = paramMap['id'];
	$("#backList").click(function(){
		var url=server_url+'/orderManage/list.do';
		tl_config.last_url=url;
		tl_config.loadToWorkArea(url);
	});


	$.ajax({
		type : 'GET',
		contentType : 'application/json',
		async : false,
		data : {
			orderId : id,
			token:token
		},
		url : server_url+'/rest/orderManage/getOrder.do?ran='+Math.random(),
		dataType : 'json',
		success : function(data) {
			if (data.retCode == "0000") {
				pasteData(data.data);
			} else{
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
			}
		}
	});
	
});

function isEmpty(data){
	if(data==null||data==undefined||data.length==0){
		return true;
	}else{
		return false;
	}
}
function pasteData(data){
	console.log(data);
    var order=data.order.data;

    $("#id").val(order.lstOrderDetail[0].orderID);
	$("#orderCode").text(order.orderCode);
	$("#orderStatusName").text(order.orderStatusName);
	$("#usersName").text(order.usersName);
	$("#preRecvTime").val(order.preRecvTime);
	$("#remark").text(order.remark);
	$("#price").val(order.price);
	$("#recvPrice").val(order.recvPrice);

    mapIfExist(function(dt){
        $("<option value="+dt.dicValue+">"+dt.dicName+"</option>").appendTo("#approveStatus");
    }, data.approveStatus);
	mapIfExist(function(dt){
		$("<option value="+dt.staffId+">"+dt.staffName+"</option>").appendTo("#staffModify");
	}, data.staff.data);

	$("#staffModify").val(order.staffId);
	$("#staff").val(order.staffName);
	$("#approveStatus").val(order.approveStatus);
	$("#salesPerson").val(order.salesPerson);
	$("#orderManager").val(order.orderManager);
	$("#seriviceFee").val(order.seriviceFee);
	$("#paidImgUrl11").attr("src",order.paidImgUrl1);
	$("#paidImgUrl22").attr("src",order.paidImgUrl2);
	$("#orderRemark").val(order.orderRemark);

	$("#searchFinishedRemark").val(order.searchFinishedRemark);
	$("#searchFinishedDate").val(order.searchFinishedDate);

	$("#searchFinishedImg1").attr("src",order.searchFinishedImg1);
	$("#searchFinishedImg2").attr("src",order.searchFinishedImg2);


	$("#paidRemark").val(order.paidRemark);
	$("#payTime").val(order.payTime);
	$("#paidImgUrl1").attr("src",order.paidImgUrl1);
	$("#paidImgUrl2").attr("src",order.paidImgUrl2);

	$("#deliveRemark").val(order.deliveRemark);
	$("#sendTime").val(order.sendTime);
	$("#deliveImgUrl1").attr("src",order.deliveImgUrl1);
	$("#deliveImgUrl2").attr("src",order.deliveImgUrl2);


	$("#confirmRemark").val(order.confirmRemark);
	$("#confirmTime").val(order.confirmTime);
	$("#confirmImg1").attr("src",order.confirmImg1);
	$("#confirmImg2").attr("src",order.confirmImg2);


	$("#comResult").text(order.comResultName);
	$("#comment").text(order.comment);

	$("#commResult").val(order.comResult);
	$("#commmentpop").text(order.comment);

	$("#picturePath1").attr("src",order.lstOrderDetail[0].skuProductVo.picturePath1);
	$("#picturePath2").attr("src",order.lstOrderDetail[0].skuProductVo.picturePath2);
	$("#picturePath3").attr("src",order.lstOrderDetail[0].skuProductVo.picturePath3);


var details = order.lstOrderDetail;
	console.log(details);
	if(exist(details)){
		_.map(details,function(obj){
			var actProductNum=parseFloat(obj.actProductNum);
			if(isNaN(actProductNum)){
				actProductNum=0.00;
			}
			var actPrice=parseFloat(obj.actPrice);
			if(isNaN(actPrice)){
				actPrice=0.00;
			}
			$("<tr><td style='padding: 0px 0;'>"+obj.productName+"</td> " +
					"<td style='padding: 0px 0;'>"+parseFloat(obj.productNum)+"</td>  " +
                    "<td style='padding: 0px 0;'><input type='hidden' id='orderDetailId' name='orderDetailId' value="+obj.id+" /><input disabled='disabled' style='width:80px;height:30px;border: 1px solid #ededed; text-align: center;' type='text' name='actProductNum_"+obj.id+"' id='actProductNum_"+obj.id+"' value='"+actProductNum+"'>"+
					"<td style='padding: 0px 0;'>"+"头"+"</td>  " +
					"<td style='padding: 0px 0;'>"+obj.productPrice+"</td>  " +
                    "<td style='padding: 0px 0;'><input disabled='disabled' style='width:80px;height:30px;border: 1px solid #ededed; text-align: center;' type='text' name='actPrice_"+obj.id+"' id='actPrice_"+obj.id+"' value='"+actPrice+"'>"+
					"<td style='padding: 0px 0;'>"+obj.price+"</td>  " +
					"<td style='padding: 0px 0;'>"+obj.supplyVo.supplyName+"</td>  " +
					"<td style='padding: 0px 0;'>"+(obj.supplyVo.provinceName+obj.supplyVo.cityName)+"</td>" +
					"</tr>").appendTo($("#productTable"));
		});
	}

};
function back(){
	var url=server_url+'orderManage/list.do';
	tl_config.loadToWorkArea(url);
}

//刷新当前页面
var reloadFn = function(){
	window.location.reload();
};
